<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>深拷贝</title>
  </head>
  <body></body>
  <script>
    var r = {
      a: "a",
      b: [1, 2, 3],
      c: {
        d: [1, 2, 3],
      },
    };
    c = {};
    function sK(r, c) {
      for (const key in r) {
        var itme = r[key];
        if (typeof itme == "object") {
          c[key] = {};
          sK(itme, c[key]);
        } else if (typeof itme == "array") {
          c[key] = [];
          sK(itme, c[key]);
        } else {
          c[key] = itme;
        }
      }
      return c;
    }

    console.log(sK(r, c));
  </script>
</html>
